package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.SelecterDetails;
import com.jss.lanouhn.fristapp.modles.SearchContent;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/9/5.
 */
public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchContentViewHolder>{
    private Context context;
    private SearchContent content;

    public SearchAdapter(Context context, SearchContent content) {
        this.context = context;
        this.content = content;
    }

    @Override
    public SearchContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_selecte_grid,null);
        SearchContentViewHolder holder=new SearchContentViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SearchContentViewHolder holder, int position) {
        final SearchContent.DataBean.ItemsBean bean=content.getData().getItems().get(position);
        holder.tv_info.setText(bean.getName());
        holder.tv_money.setText(bean.getPrice()+"");
        holder.tv_likes.setText(bean.getLikes_count()+"");
        Picasso.with(context).load(bean.getCover_image_url()).into(holder.iv_selecter);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,SelecterDetails.class);
                intent.putExtra("id",bean.getId()+"");
                context.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return content.getData().getItems().size();
    }

    public class SearchContentViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_selecter;
        private TextView tv_info,tv_money,tv_likes;
        public SearchContentViewHolder(View itemView) {
            super(itemView);
            iv_selecter= (ImageView) itemView.findViewById(R.id.iv_item_selecter);
            tv_info= (TextView) itemView.findViewById(R.id.tv_item_selecter);
            tv_money= (TextView) itemView.findViewById(R.id.tv1_item_selecter);
            tv_likes= (TextView) itemView.findViewById(R.id.tv2_item_selecter);
        }
    }
}
